home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4738 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.1 KB

  1. Path: news.compuserve.com!newsmaster
  2. From: 71024.1713@compuserve.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: for loop question
  5. Date: Wed, 31 Jan 1996 22:39:54 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4eor22$r83@dub-news-svc-5.compuserve.com>
  8. References: <4emqf8$470@opal.southwind.net>
  9. NNTP-Posting-Host: hd83-002.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. kurtg@southwind.net (Kurt Graber) wrote:
  13.  
  14. >I am currently learning c++ so maybe you gurus can answer this
  15. >also I am using borland turbo c++ 3.0
  16. >I can't get the following code to give me any output.
  17.  
  18. >#include <iostream.h>
  19.  
  20. >void main (void)
  21. >{
  22. >   int a;
  23. >   for(a = 0;a == 10;a++)
  24. >   {
  25. >    cout << "anything";
  26. >   }
  27. >}
  28.  
  29. >///If I change the loop to     for(a=0;a<=10;a++)
  30. >   the program will work fine.   
  31. >   why?????????
  32. >    thanks 
  33. >         kurt
  34.  
  35. Kurt,
  36.   The reason the first example doesn't work is that in a for loop
  37. the second part, a==10 in this case, has to be true or the for loop
  38. ends.  So in other words a for loop works as follows, while the second
  39. part is true, do the third and loop.
  40.  
  41. John
  42.  
  43.  
  44.